require("../../assets/css/index.less");
require("./home.less");
require("../../assets/fonts_two/iconfont");
var icon = require("../../assets/lib/swiper/icon");
require("../../assets/lib/swiper/swiper-bundle.min.css");
var Swiper = require("../../assets/lib/swiper/swiper-bundle.min");
require("../../utils/dom");
const axios = require("axios");
require('../../utils/https');
const { footer, color } = require("../../utils/dom");
axios.defaults.headers.common['Authorization'] = "Bearer " + JSON.parse(localStorage.getItem("token"));
var mySwiper = new Swiper('.swiper', {
    // direction: 'vertical', // 垂直切换选项
    loop: true, // 循环模式选项

    // 如果需要分页器
    pagination: {
        el: '.swiper-pagination',
    },
    pagination: {
        el: ".swiper-pagination",
        clickable: true,
    },
    autoplay: {
        delay: 1000,
        disableOnInteraction: false,
    }
});

function $(a) {
    return document.querySelector(a);
}

function $$(a) {
    return document.querySelectorAll(a);
}

async function Clock_Data() {
    const res = await axios.get("/api/user/clockInInfo", )
    console.log(res.data.data.clockCount);
    $(".day").textContent = res.data.data.clockCount;
}
Clock_Data();

async function userData() {
    const res = await axios.get("/api/user/info")
        // console.log(res.data.data);
    $("#ranking").textContent = res.data.data.ranking;
    $(".number").textContent = res.data.data.badges;
};
userData();

$(".ranking .right button").addEventListener("click", function() {
    // console.log(1);
    async function Clock_In() {
        const res = await axios.post("/api/user/clockIn")
        console.log(res.data);
        if (res.data.errno === 0) {
            $(".box").classList.remove("none")
            setInterval(() => {
                $(".box").classList.add("none")
            }, 3000);
            Clock_Data();
        } else {
            $(".box_two").classList.remove("none")
            setInterval(() => {
                $(".box_two").classList.add("none")
            }, 3000)
        }
    }
    Clock_In();
});

footer();

$("footer").addEventListener("click", function(e) {
    // console.log(e.target.nodeName);
    e.target.classList.add("active");
})